package graph.net.internal;


import graph.net.commands.CommandName;

import java.util.HashMap;
import java.util.Map;



/**
 * @author amahmood
 *
 */
public class HelpReference
{

    private static final String FROM_TO_PRAM_HELP = "(from as char, to as char).";

    Map<CommandName, String> helpReference = new HashMap<CommandName, String>();

    private static HelpReference instance = null;

    /**
     * @return
     */
    public static HelpReference getInstance()
    {
        if (instance == null)
        {
            synchronized (HelpReference.class)
            {
                if (instance == null)
                    instance = new HelpReference();
            }
        }

        return instance;
    }

    /**
     * 
     */
    private HelpReference()
    {
        helpReference.put(CommandName.add_route, CommandName.add_route.label()
                + "(from as char to as char distance as number) e.g. ab5.");
        helpReference.put(CommandName.find_all_paths_less_then_distance, CommandName.find_all_paths_less_then_distance.label()
                + FROM_TO_PRAM_HELP);
        helpReference.put(CommandName.find_distance, CommandName.find_distance.label() + "node1-node2-node3....");
        helpReference.put(CommandName.find_paths_with_exact_stops, CommandName.find_paths_with_exact_stops.label()
                + "(from as char, to as char, stops as number)");
        helpReference.put(CommandName.find_all_paths_less_then_distance, CommandName.find_all_paths_less_then_distance.label()
                + "(from as char, to as char, stops as number)");
        helpReference.put(CommandName.find_paths_with_max_stops, CommandName.find_paths_with_max_stops.label()
                + "(from as char, to as char, stops as number)");
        helpReference.put(CommandName.find_shortest_path_length, CommandName.find_shortest_path_length.label() + FROM_TO_PRAM_HELP);
        helpReference.put(CommandName.bye, CommandName.bye.label());
        helpReference.put(CommandName.exit, CommandName.exit.label());
        helpReference.put(CommandName.shutdown, CommandName.shutdown.label() + "(admin password)");
    }

    /**
     * @param command
     * @return
     */
    public String getHelp(CommandName command)
    {
        String out = "";

        out = helpReference.get(command);

        return out;
    }

    /**
     * @param commandLabel
     * @return
     */
    public String getHelp(String commandLabel)
    {
        String out = "";

        try
        {
            CommandName command = CommandName.valueOf(commandLabel);
            out = helpReference.get(command);
        }
        catch (Exception e)
        {
            System.err.println("Unknown command " + commandLabel);
        }

        return out;
    }
}
